package me.ywy.kotlinvideo.ui.activity

import android.content.Intent
import com.ashokvarma.bottomnavigation.BottomNavigationBar
import kotlinx.android.synthetic.main.activity_main.*
import me.ywy.kotlinvideo.R
import me.ywy.kotlinvideo.base.BaseActivity
import com.ashokvarma.bottomnavigation.BottomNavigationItem
import kotlinx.android.synthetic.main.tool_bar.*
import me.ywy.kotlinvideo.utils.FragmentUtil
import me.ywy.kotlinvideo.utils.ToolBarManager


class MainActivity : BaseActivity(),ToolBarManager {



    override val toolbar by lazy {
        tool_bar
    }

    override fun getLayoutId(): Int = R.layout.activity_main


    override fun initView() {


        choosePage(0)

        bottom_navigation_bar
                .addItem(BottomNavigationItem(R.mipmap.ic_bottom_home_icon, "首页").setActiveColorResource(R.color.lightred))
                .addItem(BottomNavigationItem(R.mipmap.ic_bottom_mv_unselect, "MV").setActiveColorResource(R.color.teal))
                .addItem(BottomNavigationItem(R.mipmap.ic_bottom_vlist_unselect, "V榜").setActiveColorResource(R.color.blue))
                .addItem(BottomNavigationItem(R.mipmap.ic_bottom_mvlist_unselect, "悦单").setActiveColorResource(R.color.brown))
                .setFirstSelectedPosition(if (0 > 3) 3 else 0)
                .initialise()

    }

    override fun initListener() {
        bottom_navigation_bar.setTabSelectedListener(object:BottomNavigationBar.OnTabSelectedListener{
            override fun onTabReselected(position: Int) {
            }

            override fun onTabUnselected(position: Int) {
            }

            override fun onTabSelected(position: Int) {
                choosePage(position)
            }
        })
    }

    fun choosePage(position:Int){
        supportFragmentManager.beginTransaction().replace(R.id.continer_main_layout , FragmentUtil.fragmentUtil.getFragment(position), position.toString()).commit()
    }

    override fun initData(intent: Intent) {
        initMainToolBar()
    }


}
